package com.setdemo;

public class Scholar implements Comparable<Scholar>{
    private String name;
    private int age;
    private double chinese;
    private double math;
    private double english;

    public Scholar() {
    }

    public Scholar(String name, int age, double chinese, double math, double english) {
        this.name = name;
        this.age = age;
        this.chinese = chinese;
        this.math = math;
        this.english = english;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getChinese() {
        return chinese;
    }

    public void setChinese(double chinese) {
        this.chinese = chinese;
    }

    public double getMath() {
        return math;
    }

    public void setMath(double math) {
        this.math = math;
    }

    public double getEnglish() {
        return english;
    }

    public void setEnglish(double english) {
        this.english = english;
    }

    @Override
    public String toString() {
        return "Scholar{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", chinese=" + chinese +
                ", math=" + math +
                ", english=" + english +
                '}';
    }

    @Override
    /*
        按照总分从高到低输出到控制台
        如果总分一样，按照语文成绩排
        如果语文成绩一样，按照数学成绩排
        如果数学成绩一样，按照英语成绩排
        如果英文成绩一样，按照年龄排
        如果年龄一样，按照姓名的字母顺序排
        如果都一样，认为是同一个学生，不存。
     */
    public int compareTo(Scholar o) {
        double sum1=this.getChinese()+this.getMath()+this.getEnglish();
        double sum2=o.getChinese()+o.getMath()+o.getEnglish();
        double v = sum2 - sum1;
        //如果总分一样，按照语文成绩排
        v=v==0.0?this.getChinese()-o.getChinese():v;
        //如果语文一样，按照数学成绩排
        v=v==0.0?this.getMath()-o.getMath():v;
        //如果数学成绩一样，按照英语成绩排
        v=v==0.0?this.getEnglish()-o.getEnglish():v;
        //如果英文成绩一样，按照年龄排
        v=v==0.0?this.getAge()-o.getAge():v;
        //如果年龄一样，按照姓名的字母顺序排
        v=v==0.0?this.getName().compareTo(o.getName()):v;
        if(v>0){
            v=1;
        }else if(v<0){
            v=-1;
        }else {
            v=0;
        }
        return (int) v;
    }
}
